<!doctype html>
<html>
	<head>
		<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1, minimum-scale=1,maximum-scale=1"/>

		<title>Socket.IO chat</title>
		<style>
			* { margin: 0; padding: 0; box-sizing: border-box; }
			body { font: 13px Helvetica, Arial; }
			form { background: #eee; padding: 3px; position: fixed; bottom: 0; width: 100%; }
			form input { border: 0; padding: 10px; width: 70%; }
			form button { width: 30%; background: #0cf; color:#fff; border: none; padding: 10px; }
			#messages { list-style-type: none; margin: 0; padding: 0; }
			#messages li { padding: 5px 10px; }
			#messages li:nth-child(odd) { background: #eee; }
		</style>
	</head>
	
	<body>
		<ul id="messages"></ul>
		
		<form action="">
			<input id="m" autocomplete="off" /><button>Send</button>
		</form>
		
		<script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>
		<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
		
		<script>
			var socket = io();
			$('form').submit(function(){
				socket.emit('chat', $('#m').val());
				$('#m').val('');
				return false;
			});
			
			socket.on('chat', function(msg){
				$('#messages').append($('<li>').text(msg));
			});
		</script>
		
	</body>
</html>
